package com.kingdee.eas.xbwebservice.client;

import org.apache.axis.client.Call;

import com.kingdee.eas.tools.datatask.client.webservice.EASLogin.EASLoginProxyServiceLocator;

/**
 * @author lifetime
 * 
 */
public class WebServiceClient {
	private boolean isLogin;
	private Call loginCall;

	public boolean login(XbangServiceInfo xbangServiceInfo) throws Exception {
		EASLoginProxyServiceLocator loginProxyServiceLocator = new EASLoginProxyServiceLocator(xbangServiceInfo.serverIPAddress);
		loginProxyServiceLocator.getEASLogin().login(xbangServiceInfo.userName, xbangServiceInfo.userPwd == null ? "" : xbangServiceInfo.userPwd,
				xbangServiceInfo.easSolutionName, xbangServiceInfo.dateCenterNumber, xbangServiceInfo.language, xbangServiceInfo.dbType);
		loginCall = (Call) loginProxyServiceLocator.createCall();
		if (loginCall != null) {
			setLogin(true);
		} else {
			setLogin(false);
		}
		return isLogin();
	}

	public Object callMethod(XbangServiceInfo xbangServiceInfo) throws Exception {
		loginCall.setOperationName(xbangServiceInfo.operationName);
		loginCall.setTargetEndpointAddress("http://" + xbangServiceInfo.serverIPAddress + ":" + xbangServiceInfo.serverPort
				+ "/ormrpc/services/WSXBWebServiceFacade");
		return loginCall.invoke(xbangServiceInfo.args);
	}

	public boolean isLogin() {
		return isLogin;
	}

	public void setLogin(boolean isLogin) {
		this.isLogin = isLogin;
	}

	public Call getLoginCall() {
		return loginCall;
	}

	public void setLoginCall(Call loginCall) {
		this.loginCall = loginCall;
	}

	public static Object invokeMethod(XbangServiceInfo xbangServiceInfo) throws Exception {
		EASLoginProxyServiceLocator loginProxyServiceLocator = new EASLoginProxyServiceLocator(xbangServiceInfo.serverIPAddress);
		loginProxyServiceLocator.getEASLogin().login(xbangServiceInfo.userName, xbangServiceInfo.userPwd, xbangServiceInfo.easSolutionName,
				xbangServiceInfo.dateCenterNumber, xbangServiceInfo.language, xbangServiceInfo.dbType);
		Call call = (Call) loginProxyServiceLocator.createCall();
		call.setOperationName(xbangServiceInfo.operationName);
		call.setTargetEndpointAddress("http://" + xbangServiceInfo.serverIPAddress + ":" + xbangServiceInfo.serverPort
				+ "/ormrpc/services/WSXBWebServiceFacade");
		return call.invoke(xbangServiceInfo.args);
	}

}
